home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
-
- #include "wlib.h"
- #include "parts.h"
-
- /*
- proto -s textmap.c > temp
- */
- static int TextMapExec( WindowID, EventInfo* );
-
- typedef struct {
- int colums, lines ;
- int attr, font ;
- char *buf ;
- }
- TextMap ;
-
- WindowID TextMapOpen( x, y, colums, lines, parent, attr, font )
- int x, y, colums, lines ;
- WindowID parent ;
- int attr, font ;
- {
- WindowID wp ;
- TextMap *p ;
- int i, len ;
-
- wp = WindowOpen( x, y, colums * font / 2, lines * font, parent, TextMapExec );
- p = malloc( sizeof( TextMap ) );
- if ( p == NULL )
- return( NULL );
- p->buf = malloc( lines * ( colums + 1 ) );
- if ( p->buf == NULL )
- {
- free( p );
- return( NULL );
- }
- len = colums + 1 ;
- for( i = 0 ; i < lines ; ++i )
- {
- memset( p->buf + i * len, ' ', colums );
- p->buf[ i * len + colums ] = '\0' ;
- }
-
- p->colums = colums ;
- p->lines = lines ;
- p->attr = attr ;
- p->font = font ;
- WindowSetClientData( wp, 0, p );
- return( wp );
- }
-
- void TextMapClose( wp )
- WindowID wp ;
- {
- TextMap *p ;
-
- p = WindowGetClientPointer( wp );
- free( p->buf );
- free( p );
- }
-
- static int TextMapExec( wp, info )
- WindowID wp ;
- EventInfo *info ;
- {
- int i, j, n, len ;
- DrawBuf buf[10], *bufp ;
- TextMap *p ;
-
- p = WindowGetClientPointer( wp );
- switch( info->option )
- {
- case EventRedraw :
- DrawSetClear( buf, 1 );
- WindowDraw( wp, buf, 1 );
- i = info->y / p->font ;
- n = ( info->y + info->v ) / p->font + 1 ;
- if ( n >= p->lines )
- n = p->lines - 1 ;
- len = p->colums + 1 ;
- while( i <= n )
- {
- bufp = buf ;
- for( j = 0 ; j < 10 ; ++j )
- {
- DrawSetSymbol( bufp++, 0, i * p->font, p->buf + i*len, p->attr, p->font );
- if ( ++i > n )
- break ;
- }
- WindowDraw( wp, buf, bufp-buf );
- }
- break ;
- }
- return( TRUE );
- }
-
- void TextMapPutString( wp, x, y, str )
- WindowID wp ;
- int x, y ;
- char *str ;
- {
- TextMap *p ;
- int len ;
-
- p = WindowGetClientPointer( wp );
- len = p->colums + 1 ;
- memcpy( p->buf + y*len + x, str, strlen( str ) );
- }
-